package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.MesMatbom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.MesSordProdMapper;
import com.ruoyi.system.domain.MesSordProd;
import com.ruoyi.system.service.IMesSordProdService;

/**
 * 销售订单产品Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-01
 */
@Service
public class MesSordProdServiceImpl implements IMesSordProdService 
{
    @Autowired
    private MesSordProdMapper mesSordProdMapper;

    /**
     * 查询销售订单产品
     * 
     * @param id 销售订单产品主键
     * @return 销售订单产品
     */
    @Override
    public MesSordProd selectMesSordProdById(Integer id)
    {
        return mesSordProdMapper.selectMesSordProdById(id);
    }

    /**
     * 查询销售订单产品列表
     * 
     * @param mesSordProd 销售订单产品
     * @return 销售订单产品
     */
    @Override
    public List<MesSordProd> selectMesSordProdList(MesSordProd mesSordProd)
    {
        return mesSordProdMapper.selectMesSordProdList(mesSordProd);
    }

    /**
     * 新增销售订单产品
     * 
     * @param mesSordProd 销售订单产品
     * @return 结果
     */
    @Override
    public int insertMesSordProd(MesSordProd mesSordProd)
    {
        List<MesSordProd> mtrs = mesSordProd.getMtrs();

        for (MesSordProd mtr : mtrs) {
            //1：处理数据
            mtr.setProdId(mtr.getProdId());//产品编码
            mtr.setSordId(mtr.getSordId());//销售订单编码
            mtr.setProdNum(mtr.getProdNum());
            //2.sql插入
            mesSordProdMapper.insertMesSordProd(mtr);
        }
        return 1;

    }

    /**
     * 修改销售订单产品
     * 
     * @param mesSordProd 销售订单产品
     * @return 结果
     */
    @Override
    public int updateMesSordProd(MesSordProd mesSordProd)
    {
        return mesSordProdMapper.updateMesSordProd(mesSordProd);
    }

    /**
     * 批量删除销售订单产品
     * 
     * @param ids 需要删除的销售订单产品主键
     * @return 结果
     */
    @Override
    public int deleteMesSordProdByIds(Integer[] ids)
    {
        return mesSordProdMapper.deleteMesSordProdByIds(ids);
    }

    /**
     * 删除销售订单产品信息
     * 
     * @param id 销售订单产品主键
     * @return 结果
     */
    @Override
    public int deleteMesSordProdById(Integer id)
    {
        return mesSordProdMapper.deleteMesSordProdById(id);
    }

    /******/
    @Override
    public List<String> selectProdId(String sordId){
        return mesSordProdMapper.selectProdId(sordId);
    }

    //修改原料bom
    @Override
    public int editSordProd(MesSordProd mesSordProd) {


        mesSordProdMapper.deleteMesSordProdByOldSordId(mesSordProd.getOldSordId());

        List<MesSordProd> mtrs = mesSordProd.getMtrs();
        for (MesSordProd mtr : mtrs) {
            //1：处理数据
            mtr.setProdId(mtr.getProdId());//产品编码
            mtr.setSordId(mtr.getSordId());//销售订单编码
            mtr.setProdNum(mtr.getProdNum());
            //2.sql插入
            mesSordProdMapper.insertMesSordProd(mtr);
        }
        return 1;
    }


}
